package com.lagou.rocket.demo.enums;

import java.util.HashMap;
import java.util.Map;

public enum OrderStatus {
    CREATE(0, "已创建"),
    PAYED(10, "已支付"),
    CANCEL(30, "已取消");

    private Integer code;
    private String name;


    OrderStatus(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    private static final Map<Integer, OrderStatus> CACHE = new HashMap<Integer, OrderStatus>();

    static {
        for (OrderStatus val : OrderStatus.values()) {
            CACHE.put(val.getCode(), val);
        }
    }

    /**
     * 根据code值来转换为枚举类型
     */
    public static OrderStatus parse(Integer code) {
        return CACHE.get(code);
    }

}